package com.ternnetwork.oa.entity.settings;


import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ternnetwork.commons.utils.JsonDateSerializer;
import com.ternnetwork.core.accesscontroll.entity.User;
import com.ternnetwork.oa.entity.work.Event;
import com.ternnetwork.oa.entity.work.EventUserId;
import com.ternnetwork.oa.enums.settings.UserRelationshipType;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table(name="OA_USER_RELATIONSHIP")
@Data
public class UserRelationship {
    @EmbeddedId
    @AttributeOverrides( {
            @AttributeOverride(name="userIdFrom", column=@Column(name="USER_ID_FROM", nullable=false) ),
            @AttributeOverride(name="userIdTo", column=@Column(name="USER_ID_TO", nullable=false) ) ,
            @AttributeOverride(name="type", column=@Column(name="TYPE", nullable=false) )} )

    private UserRelationshipId id;

    @ManyToOne
    @JoinColumn(name="USER_ID_FROM", nullable=false, insertable=false, updatable=false)
    private User userFrom;
    @ManyToOne
    @JoinColumn(name="USER_ID_TO", nullable=false, insertable=false, updatable=false)
    private User userTo;

    @Column(name="TYPE", insertable=false, updatable=false)
    private UserRelationshipType type;

    @Column(name="CREATED_BY_ID")
    private Long createdById;

    @Column(name="CREATE_TIME")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    @JsonSerialize(using= JsonDateSerializer.class)
    public Date getCreateTime() {
        return createTime;
    }

    public UserRelationship(User userFrom) {
        this.userFrom = userFrom;
    }

    public UserRelationship() {
        super();
    }
}
